package com.hc.conferencecheck.utils;

import java.util.Random;

/**
 * 验证码相关工具类
 */
public class VerificationCodeUtils {
    /**
     * 生成验证码
     */
    public static String createVerificationCode() {
        //随机验证码
        String verificationCode = "";
        //从0-9数组中选取六位验证码
        int[] intArr = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 0};

        //生成六个随机数，分别从数组中取六次，拼接为随机验证码
        Random random = new Random();
        for (int i = 0; i < 6; i++) {
            //因为数组的长度最大为9，所以随机数最大取到9
            int randomInt = random.nextInt(10);
            int element = intArr[randomInt];
            //拼接验证码
            verificationCode += element;
        }
        System.out.println(verificationCode);
        return verificationCode;
    }
}
